package org.wiw.client.gui;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HorizontalPanel;

public abstract class AbstractOkCancelDialog extends AbstractDialogBox{
	private Button okButton;
	private Button cancelButton;
	private IDialogHandler handler;
	
	public AbstractOkCancelDialog(String title) {
		super(title);
		
		okButton = new Button("Ok");
		okButton.setFocus(true);
		
		okButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				hide();
				okPressed();
			}
		});
		
		cancelButton = new Button("Cancel");
		cancelButton.setFocus(true);
		
		cancelButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				hide();
				cancelPressed();
			}
		});
		
		HorizontalPanel dialogHPanel = new HorizontalPanel();
		dialogHPanel.addStyleName("dialogHPanel");
		
		dialogHPanel.add(okButton);
		dialogHPanel.add(cancelButton);
		
		dialogPanel.add(dialogHPanel);
	}
	
	@Override
	public void show() {
		createContent();
		super.show();
	}
		
	private void okPressed(){
		if(handler != null) handler.okPressed();
	}
	
	private void cancelPressed(){
		if(handler != null) handler.cancelPressed();
	}

	public void setHandler(IDialogHandler handler) {
		this.handler = handler;
	}
}
